    <template>

    <div class="app-container" v-if="canList">
        <div class="filter-container">


            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="手机号码"
                      v-model="listQuery.entity.user.mobile">
            </el-input>
            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="姓名"
                      v-model="listQuery.entity.user.name">
            </el-input>
            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="编码"
                      v-model="listQuery.entity.user.code">
            </el-input>
            <!--            <el-input  style="width: 200px;" class="filter-item input"-->
            <!--                      placeholder="推荐人编码"-->
            <!--                      v-model="listQuery.entity.referer.code">-->
            <!--            </el-input>-->
            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="供货商编码"
                      v-model="listQuery.entity.topUser.code">
            </el-input>


            <el-select @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                       v-model="listQuery.entity.level.name"
                       placeholder="级别">
                <el-option v-for="(item,index) in  levels" :key="index" :label="item.name" :value="item.name">
                </el-option>
            </el-select>

            <el-select @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                       v-model="listQuery.entity.user.status"
                       placeholder="状态">
                <el-option v-for="(item,index) in  statusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>
            <el-date-picker
                    class="filter-item input"
                    v-model="listQuery.entity.user.times"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="加入时间开始日期"
                    end-placeholder="加入时间结束日期">
            </el-date-picker>

            <div style="display: inline-block">

                <el-button style="margin-left: 10px;" class="filter-item" type="primary" v-waves icon="el-icon-search"
                           @click="handleFilter">查找
                </el-button>

                <el-button   style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-upload2"
                           @click="openFile">批量转卷
                </el-button>

                <!--                <el-button class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary"-->
                <!--                           v-if="canSave" icon="el-icon-edit">添加-->
                <!--                </el-button>-->
                <!--                <el-button class="filter-item" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download"-->
                <!--                           @click="handleDownload">导出-->
                <!--                </el-button>-->
                <input style="display: none" ref="file" @change="upload" type="file">

            </div>
        </div>

        <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
                  style="margin-bottom: 20px">
            <el-table-column align="center" label="序号">
                <template slot-scope="scope">
                    <span>{{scope.row.user.id}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="微信Openid">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.openId}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="微信统一ID">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.unionId}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="微信头像">
                <template slot-scope="scope">
                    <img style="height: 50%;width: 50%" :src="scope.row.user.avatar">
                </template>
            </el-table-column>
            <el-table-column align="center" label="手机号码" width="110">
                <template slot-scope="scope">
                    <span>{{scope.row.user.mobile}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="名称">
                <template slot-scope="scope">
                    <span>{{scope.row.user.name}}-{{scope.row.user.code}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="编码" width="100">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.code}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="推荐人" width="140">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span v-if="scope.row.referer">{{scope.row.referer.code}}-{{scope.row.referer.name}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="供货商" width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.topUser">{{scope.row.topUser.code}}-{{scope.row.topUser.name}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="团队树">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.team}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="级别名称">
                <template slot-scope="scope">
                    <span v-if="scope.row.level">{{scope.row.level.name}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="状态">
                <template slot-scope="scope">
                                                <span>

                         <el-tag :type="tagTypes[scope.row.user.status]">     {{statusOptions[scope.row.user.status]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="加入时间" width="100">
                <template slot-scope="scope">
                    <span>{{parseTime(scope.row.user.time)}}</span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="操作" width="300" class-name="small-padding fixed-width">
                <template slot-scope="scope">

                    <el-button v-if="canOrderTransfer" type="warning" size="mini" @click="handleTransfer(scope.row)">转货
                    </el-button>

                    <el-button v-if="canAccountTransfer" type="warning" size="mini" @click="handleRecharge(scope.row)">转账
                    </el-button>


                    <el-button type="success" size="mini" @click="handleAccount(scope.row)">账户
                    </el-button>

                    <el-button type="primary" v-if="canUpdate" size="mini" @click="handleUpdate(scope)">编辑
                    </el-button>

                    <!--                    <el-button v-if="canSave" size="mini" type="danger"-->
                    <!--                               @click="handleDelete(scope)">删除-->
                    <!--                    </el-button>-->
                </template>
            </el-table-column>

        </el-table>

        <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                           layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>


        <el-dialog title="账户" :visible.sync="dialogAccountVisible">
            <!--            <el-card class="box-card">-->
            <!--                <div slot="header" class="clearfix">-->
            <!--                    <span>资金账户</span>-->
            <!--                </div>-->

            <!--            </el-card>-->

            <el-card class="box-card" style="padding-bottom: 24px">
                <div slot="header" class="clearfix">
                    <span>产品账户</span>
                    <!--                    <el-button @click="addTransfer" style="float: right; padding: 3px 0" type="text">添加</el-button>-->
                </div>

                <el-table border :data="storeList" fit>
                    <el-table-column align="center" label="产品">

                        <template slot-scope="scope">
                            <span>{{scope.row.goods.name}}</span>
                        </template>

                    </el-table-column>
                    <el-table-column
                            align="center"
                            label="数量">
                        <template slot-scope="scope">
                            <span>{{scope.row.store.quantity}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            align="center"
                            label="冻结">
                        <template slot-scope="scope">
                            <span>{{scope.row.store.lockQuantity}}</span>
                        </template>
                    </el-table-column>
                </el-table>


            </el-card>

            <el-card class="box-card" style="padding-bottom: 24px;margin-top: 24px">
                <div slot="header" class="clearfix">
                    <span>资金账户</span>
                    <!--                    <el-button @click="addTransfer" style="float: right; padding: 3px 0" type="text">添加</el-button>-->
                </div>
                <el-table border :data="accountList" fit>
                    <el-table-column align="center" label="账户名">

                        <template slot-scope="scope">
                            <span>{{accountOptions[scope.row.type]}}</span>
                        </template>

                    </el-table-column>
                    <el-table-column
                            align="center"
                            label="数量">
                        <template slot-scope="scope">
                            <span>{{scope.row.amount}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column
                            align="center"
                            label="冻结">
                        <template slot-scope="scope">
                            <span>{{scope.row.lockAmount}}</span>
                        </template>
                    </el-table-column>
                </el-table>
            </el-card>

            <span slot="footer" class="dialog-footer">
<!--    <el-button @click="dialogTransferVisible = false">取 消</el-button>-->
                <!--    <el-button type="primary" @click="transferGoods">确 定</el-button>-->
  </span>

        </el-dialog>

        <el-dialog title="转账" :visible.sync="dialogRechargeVisible" v-if="recharge">
            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <span>人员信息</span>
                </div>
                <el-form label-width="100px" :inline="true">


                    <el-form-item label="转出方">
                        <el-input v-model="recharge.fromUser.code" placeHolder="编号"></el-input>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-input v-model="recharge.fromUser.name" placeHolder="名字"></el-input>
                    </el-form-item>

                    <!--                <el-divider class="box-card"><i class="el-icon-bottom"></i></el-divider>-->
                    <el-form-item label="接收方">
                        <el-input v-model="recharge.toUser.code" placeHolder="编号"></el-input>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-input v-model="recharge.toUser.name" placeHolder="名字"></el-input>
                    </el-form-item>
                </el-form>
            </el-card>

            <el-card class="box-card" style="margin-top: 24px">
                <div slot="header" class="clearfix">
                    <span>转账信息</span>
                    <!--                    <el-button @click="addTransfer" style="float: right; padding: 3px 0" type="text">添加</el-button>-->
                </div>
                <el-form label-width="50px" :inline="true">

                    <el-form-item label="币种" prop="status">
                        <el-select class="filter-item" v-model="recharge.record.type" placeholder="币种">
                            <el-option v-if="item != ''" v-for="(item,index) in  accountOptions" :key="item" :label="item"
                                       :value="index">
                            </el-option>
                        </el-select>
                    </el-form-item>


                    <el-form-item label="数量">
                        <el-input v-model="recharge.record.amount"
                                  placeHolder="数量" type="number"></el-input>
                    </el-form-item>


                    <el-form-item label="备注">
                        <el-input v-model="recharge.record.info" style="width: 400px" type="textarea" :rows="2"
                                  placeHolder="备注"></el-input>
                    </el-form-item>

                </el-form>
            </el-card>

            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogRechargeVisible = false">取 消</el-button>
    <el-button type="primary" @click="commitRecharge">确 定</el-button>
  </span>

        </el-dialog>


        <el-dialog title="转货" :visible.sync="dialogTransferVisible" v-if="transfer">
            <el-card class="box-card">
                <div slot="header" class="clearfix">
                    <span>人员信息</span>
                </div>
                <el-form label-width="100px" :inline="true">


                    <el-form-item label="转出方">
                        <el-input v-model="transfer.fromUser.code" placeHolder="编号"></el-input>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-input v-model="transfer.fromUser.name" placeHolder="名字"></el-input>
                    </el-form-item>

                    <!--                <el-divider class="box-card"><i class="el-icon-bottom"></i></el-divider>-->
                    <el-form-item label="接收方">
                        <el-input v-model="transfer.user.code" placeHolder="编号"></el-input>
                    </el-form-item>
                    <el-form-item label=" ">
                        <el-input v-model="transfer.user.name" placeHolder="名字"></el-input>
                    </el-form-item>
                </el-form>
            </el-card>

            <el-card class="box-card" style="margin-top: 24px">
                <div slot="header" class="clearfix">
                    <span>选择产品</span>
                    <el-button @click="addTransfer" style="float: right; padding: 3px 0" type="text">添加</el-button>
                </div>
                <el-form label-width="50px" :inline="true">


                    <div class="" v-for="(item,index) in transfer.mallOrder.items" :key="index">


                        <el-form-item label="产品">
                            <el-select v-model="item.goodsId" filterable placeholder="请选择">
                                <el-option
                                        v-for="item in goodsOptions"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                        :disabled="item.disabled">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item label="数量">
                            <el-input v-model="item.quantity" style="width: 100px;margin-right: 24px"
                                      placeHolder=""></el-input>
                            <el-button @click.prevent="deleteTransfer(index)">删除</el-button>
                        </el-form-item>
                    </div>

                    <el-form-item label="备注">
                        <el-input v-model="transfer.mallOrder.remark" style="width: 400px" type="textarea" :rows="2"
                                  placeHolder="备注"></el-input>
                    </el-form-item>

                </el-form>
            </el-card>

            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogTransferVisible = false">取 消</el-button>
    <el-button  type="primary" @click="transferGoods">确 定</el-button>
  </span>

        </el-dialog>

        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" v-if="temp.user">
            <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
                     style='width: 450px; margin-left:50px;'>
                <el-form-item label="微信Openid" prop="openId">
                    <el-input v-model="temp.user.openId"></el-input>
                </el-form-item>
                                <el-form-item label="微信统一ID" prop="unionId">
                                    <el-input v-model="temp.user.unionId"></el-input>
                                </el-form-item>
                <!--                <el-form-item label="微信头像" prop="avatar">-->
                <!--                    <el-input v-model="temp.avatar"></el-input>-->
                <!--                </el-form-item>-->
                <el-form-item label="手机号码" prop="mobile">
                    <el-input v-model="temp.user.mobile"></el-input>
                </el-form-item>
                <el-form-item label="名称" prop="name">
                    <el-input v-model="temp.user.name"></el-input>
                </el-form-item>
                <el-form-item label="编码" prop="code">
                    <el-input v-model="temp.user.code" disabled></el-input>
                </el-form-item>
               <!-- <el-form-item label="推荐人编号" prop="rid">
                    <el-input v-model="temp.referer.code"></el-input>
                </el-form-item>-->
                <el-form-item label="供货商编号" prop="tid">
                    <el-input v-model="temp.topUser.code"></el-input>
                </el-form-item>
                <el-form-item label="团队编号" prop="rid">
                    <el-input v-model="temp.user.tCode"></el-input>
                </el-form-item>



                <el-form-item label="级别名称" prop="levelId">

                    <el-select :disabled="!canLevel" @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                               v-model="temp.user.levelId"
                               placeholder="级别">
                        <el-option v-for="(item,index) in  levels" :key="index" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

              <el-form-item label="负责人" prop="levelId">

                <el-select  @change='handleFilter' clearable class="filter-item input" style="width: 130px"
                           v-model="temp.user.vip"
                           placeholder="级别">
                  <el-option v-for="(item,index) in  options" :key="index" :label="item" :value="index">
                  </el-option>
                </el-select>
              </el-form-item>


                <el-form-item label="状态" prop="status">
                    <el-select class="filter-item" v-model="temp.user.status" placeholder="状态">
                        <el-option v-for="(item,index) in  statusOptions" :key="item" :label="item"
                                   :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="加入时间" prop="date">
                    <el-date-picker v-model="temp.user.time" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="加入时间">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="备注" prop="remark">
                    <el-input type="textarea" v-model="temp.user.remark"></el-input>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialogForm">取消</el-button>
                <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确认</el-button>
                <el-button v-else type="primary" @click="updateData">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style type="stylus">
    .filter-container {
        /*padding-bottom: 20px;*/
    }

    .filter-item {
        margin-bottom: 10px;
    }

    .box-card > .el-card__body {
        padding-bottom: 0
    }

    .filter-item.input {
        /*line-height: 60px*/
        margin-right: 10px;
    }
</style>

<script>
    import {list, save, update, remove, store,upload} from '@/api/user'
    import {all} from "../../../api/mall_goods";
    import {listAll} from "@/api/level";
    import waves from '@/directive/waves' // 水波纹指令
    import {parseTime} from '@/utils'
    import {transfer} from "@/api/mall_order";
    import {transfer as transferAccount} from "@/api/account";
    import {mapGetters} from 'vuex'
    import {hasAuth} from '@/utils/auth'
    import {all as accounts} from "@/api/account";
    // import {upload} from "../../../api/mall_order";

    export default {
        name: 'test',
        directives: {
            waves
        },
        data() {
            return {
                levels: null,
                tableKey: 0,
                list: null,
                total: null,
                listLoading: true,
                time: null,
                goodsList: [],
                storeList: [],
                accountList: [],
                transfer: null,
                recharge: {
                  fromUser:{},
                  toUser:{},
                  record:{}
                },
                listQuery: {
                    json: true,
                    page: 1,
                    limit: 20,
                    order: 'user.id desc',
                    entity: {
                        user: {
                            openId: null
                            ,
                            unionId: null
                            ,
                            avatar: null
                            ,
                            mobile: null
                            ,
                            name: null
                            ,
                            code: null
                            ,
                            rid: null
                            ,
                            team: null
                            ,
                            tCode: null
                            ,
                            levelId: null
                            ,
                            time: null,
                            times: null,
                            status: null
                        },
                        referer: {
                            name: null,
                            mobile: null,
                            code: null
                        },
                        topUser: {
                            name: null,
                            code: null,
                            mobile: null
                        },
                        level: {
                            name: null
                        }
                    }


                },
                accountOptions: ["代金券", "积分", '优惠券', '换购券','经验值',"","清货券"],
                tagTypes: ['info', '', 'warning', 'danger', 'warning'],
                statusOptions: ['正常', '禁用'],
                options: ['否', '是'],
                temp:
                    {
                        user: {
                            id: null,
                            vip:null,
                            openId: null,
                            unionId: null,
                            avatar: null,
                            mobile: null,
                            name: null,
                            code: null,
                            rid: null,
                            team: null,
                            levelId: null,
                            time: null,
                            status: null,
                            remark:null
                        },
                        topUser: {},
                        referer: {}
                    }
                ,
                dialogFormVisible: false,
                dialogTransferVisible: false,
                dialogAccountVisible: false,
                dialogRechargeVisible: false,
                dialogStatus:
                    '',
                textMap:
                    {
                        update: '修改',
                        create:
                            '新增'
                    }
                ,
                rules:
                    {
                        openId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        unionId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        avatar: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        mobile: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        name: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        code: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        rid: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        team: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        levelId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        time: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        status: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                    }
                ,
                downloadLoading: false,
                qData:
                    {
                        token: '',
                        key:
                            ''
                    }
            }
        },
        created() {

            this.getList()
            listAll().then(res => {
                this.levels = res.data
            })
        },
        computed: {
            goodsOptions() {
                let options = []
                this.goodsList.forEach(goods => {
                    if (!goods.saleType || goods.saleType != 1) {//零售产品
                        return
                    }
                    let option = {
                        label: goods.name,
                        value: goods.id
                    }
                    this.transfer.mallOrder.items.forEach(item => {
                        if (item.goodsId == goods.id) {
                            option.disabled = true
                        }
                    })
                    options.push(option)
                })
                return options
            },
            ...mapGetters([
                'perms'
            ]),
            canSave() {
                return hasAuth(this.perms, 'user:save')
            },
            canDelete() {
                return hasAuth(this.perms, 'user:delete')
            },
            canUpdate() {
                return hasAuth(this.perms, 'user:update')
            },
            canList() {
                return hasAuth(this.perms, 'user:list')
            },
            canOrderTransfer() {
                return hasAuth(this.perms, 'user:order:transfer')
            },
            canAccountTransfer() {
                return hasAuth(this.perms, 'user:account:transfer')
            },
            canLevel() {
                return hasAuth(this.perms, 'user:level')
            }
        },
        methods: {
            handleAccount(row) {
                store(row.user.id).then(res => {
                    this.storeList = res.data
                    this.dialogAccountVisible = true
                })
                accounts(row.user.id).then(res => {
                    this.accountList = res.data
                    // console.log(this.accountList)
                })
            },
            openFile() {
                this.$refs.file.click()
            },
            upload(e) {
                upload(e.target.files[0]).then(res=>{
                    this.$notify({
                        title: '成功',
                        message: '上传成功!',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            handleRecharge(row) {
                this.initRecharge()
                // Object.assign(this.recharge.toUser,{code:row.user.code,name:row.user.name})
              this.$set(this.recharge.toUser,'code',row.user.code)
              this.$set(this.recharge.toUser,'name',row.user.name)
              this.dialogRechargeVisible = true
            },
            commitRecharge() {
                transferAccount(this.recharge).then(res => {
                    this.$notify({
                        title: '成功',
                        message: '转账成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.dialogRechargeVisible = false
                })
            },
            initRecharge() {
                this.recharge = {
                    fromUser: {
                        name: '公司',
                        code: '00'
                    },
                    toUser: {

                    },
                    record: {

                    }
                }
            },
            initTransfer() {
                this.transfer = {
                    fromUser: {
                        name: '公司',
                        code: '00'
                    },
                    user: {
                        name: '',
                        code: ''
                    },
                    mallOrder: {
                        remark: '',
                        items: [{
                            goodsId: '',
                            quantity: ''
                        }]
                    }

                }
            },
            handleTransfer(row) {
                this.initTransfer()
                this.transfer.user.code = row.user.code
                this.transfer.user.name = row.user.name
                all().then(res => {
                    this.goodsList = res.data
                    this.dialogTransferVisible = true
                })
            },
            deleteTransfer(index) {
                this.transfer.mallOrder.items.splice(index, 1)

            },
            addTransfer() {
                this.transfer.mallOrder.items.push({
                    id: '',
                    quantity: ''
                })
            },
            transferGoods() {
                this.transfer.json = true
                transfer(this.transfer).then(res => {
                    this.$notify({
                        title: '成功',
                        message: '转货成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.dialogTransferVisible = false
                })
            },
            parseTime(time) {
                return parseTime(time, '{y}-{m}-{d}')
            },
            getList() {
                this.listLoading = true
                list(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.listLoading = false
                })
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleSizeChange(val) {
                this.listQuery.limit = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleModifyStatus(row, status) {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                row.status = status
            },
            beforeFormShow(row) {
                this.resetTemp(row) // 更新数据
                // 存在图片

            },
            afterFormShow(row) {

            },
            beforeFormCommit() {
            },
            resetTemp(row) {

                this.temp = {}
                if (row) {
                    this.temp = JSON.parse(JSON.stringify(row)) // copy obj
                }

            },
            handleCreate() {
                this.beforeFormShow()
                this.resetTemp()
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.afterFormShow()
                    this.$refs['dataForm'].clearValidate()
                })
            },
            handleDelete(scope) {
                this.index = scope.$index
                // this.beforeFormShow(row)
                // this.temp = Object.assign({}, row) // copy obj
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.$message({
                    //   type: 'success',
                    //   message: '删除成功!'
                    // })
                    this.deleteData()
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            },
            createData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            save(this.temp).then(res => {
                                this.temp = res.data
                                this.list.unshift(this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '创建成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            deleteData() {
                remove({ids: this.list[this.index].user.id}).then(res => {
                    // 从当前队列中移除
                    this.list.splice(this.index, 1)
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                })
            },
            handleUpdate(scope) {
                this.index = scope.$index
                this.beforeFormShow(scope.row)
                this.dialogStatus = 'update'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                })
            },
            updateData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            this.temp.json = true
                            update(this.temp).then(() => {

                                this.getList()
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '更新成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            closeDialogForm() {
                this.dialogFormVisible = false
            },
            handleDownload() {
                this.downloadLoading = true
                import('@/vendor/Export2Excel').then(excel => {
                    const tHeader = [
                        '序号'
                        ,
                        '微信Openid'
                        ,
                        '微信统一ID'
                        ,
                        '微信头像'
                        ,
                        '手机号码'
                        ,
                        '名称'
                        ,
                        '编码'
                        ,
                        '推荐人ID'
                        ,
                        '团队树'
                        ,
                        '级别名称'
                        ,
                        '状态'
                        ,
                        '加入时间'
                    ]
                    const filterVal = ['id'
                        , 'openId'
                        , 'unionId'
                        , 'avatar'
                        , 'mobile'
                        , 'name'
                        , 'code'
                        , 'rid'
                        , 'team'
                        , 'levelId'
                        ,
                        'status'
                        ,
                        'time'
                    ]
                    const data = this.formatJson(filterVal, this.list)
                    excel.export_json_to_excel({
                        header: tHeader,
                        data,
                        filename: 'table-list'
                    })
                    this.downloadLoading = false
                })
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => {
                        return v[j]
                    }
                ))
            },
        }
    }
</script>
